package com.suncnpap.library.controller;

import com.suncnpap.library.model.BorrowBook;
import com.suncnpap.library.model.ChineseClassification;
import com.suncnpap.library.model.CollectionChange;
import com.suncnpap.library.model.Library;
import com.suncnpap.library.service.BookLossService;
import com.suncnpap.library.service.BorrowBookRecordService;
import com.suncnpap.library.service.BorrowBookService;
import com.suncnpap.library.service.ChineseClassificationService;
import com.suncnpap.library.service.CollectionChangeService;
import com.suncnpap.library.service.LibraryService;
import com.suncnpap.library.service.ReturnBookService;
import com.suncnpap.reader.model.Reader;
import com.suncnpap.reader.service.ReaderService;
import com.suncnpap.reader.service.ReaderTypeService;
import com.suncnpap.statistics.annotation.LogType;
import com.suncnpap.statistics.annotation.SysLog;
import com.suncnpap.system.model.Config;
import com.suncnpap.system.service.ConfigService;

import java.text.DecimalFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.htmlcleaner.CleanerProperties;
import org.htmlcleaner.DomSerializer;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

import com.app.util.common.Format;
import com.app.util.common.HandlerResult;
import com.app.util.common.ObjUtil;
import com.app.util.common.PathUtil;
import com.app.util.common.RegUtil;
import com.app.util.common.ResponseUtil;
import com.app.util.common.UuidUtil;
import com.app.util.database.mybatis.Page;
import com.app.util.database.mybatis.QueryType;
import com.app.util.http.HttpClientUtil;
import com.suncnpap.base.common.GlobaUser;
import com.suncnpap.base.common.ParamModel;
import com.suncnpap.base.controller.BaseController;
import com.suncnpap.datamanage.common.ExportExcelUtils;

/** 
 * 说明：书库Controller
 */
@Controller
@RequestMapping(value="/library/library")
public class LibraryController extends BaseController {
	
	//private static final Logger log = Logger.getLogger(LibraryController.class);
	
	@Autowired
	LibraryService libraryService;
	
	@Autowired
	BorrowBookService borrowBookService;
	
	@Autowired
	BorrowBookRecordService borrowBookRecordService;
	
	@Autowired
	ReturnBookService returnBookService;
	
	@Autowired
	ReaderTypeService readerTypeService;
	
	@Autowired
	ReaderService readerService;
	
	@Autowired
	CollectionChangeService collectionChangeService;
	
	@Autowired
	BookLossService bookLossService;
	
	@Autowired
	ChineseClassificationService chineseClassificationService;
	
	@Autowired
	ConfigService configService;
	/**
	 * 去往列表页面
	 * @param map
	 * @return
	 */
	@RequestMapping(value="/list")
	public void list(HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		HandlerResult result = this.checkToken(request);
		
		if (result.getCode()==0) {

			Page page = this.setPage();
			
			String keyName = this.getParameter("keyName", "");
			String keywords = this.getParameter("keywords", "");
			if(!keyName.equals("")){
				page.addQueryAnd(keyName, QueryType.markLIKE, keywords);
			}
			
			String strISBN = this.getParameter("strISBN","");	//ISBN
			if(!"".equals(strISBN)){
				page.addQueryAnd("strISBN", QueryType.markLIKE, strISBN);
			}
			
			String strFirstResponsible = this.getParameter("strFirstResponsible","");	//作者
			if(!"".equals(strFirstResponsible)){
				page.addQueryAnd("strFirstResponsible", QueryType.markLIKE, strFirstResponsible);
			}
			
			String strPositiveTitle = this.getParameter("strPositiveTitle","");	//正题名
			if(!"".equals(strPositiveTitle)){
				page.addQueryAnd("strPositiveTitle", QueryType.markLIKE, strPositiveTitle);
			}
			
			String strBookBarcode=this.getParameter("strBookBarcode","");	//图书条码
			if(!"".equals(strBookBarcode)){
				page.addQueryAnd("strBookBarcode", QueryType.markLIKE, strBookBarcode);
			}
			
			String strStartBookBarcode = this.getParameter("strStartBookBarcode", "");
			if(!strStartBookBarcode.equals("")){
				page.addQueryAnd("strBookBarcode", QueryType.markGTEQ, strStartBookBarcode);
			}
			
			String strEndBookBarcode = this.getParameter("strEndBookBarcode", "");
			if(!strEndBookBarcode.equals("")){
				page.addQueryAnd("strBookBarcode", QueryType.markLTEQ, strEndBookBarcode);
			}
			
			String strClassNumber=this.getParameter("strClassNumber","");	//分类号
			if(!"".equals(strClassNumber)){
				page.addQueryAnd("strClassNumber", QueryType.markLIKE, strClassNumber);
			}
			
			String strLotNumber=this.getParameter("strLotNumber","");	//批号
			if(!"".equals(strLotNumber)){
				page.addQueryAnd("strLotNumber", QueryType.markLIKE, strLotNumber);
			}
			
			String strCollectionLocation=this.getParameter("strCollectionLocation","");	//批号
			if(!"".equals(strCollectionLocation)){
				page.addQueryAnd("strCollectionLocationId", strCollectionLocation);
			}
			
			String strOrder=this.getParameter("strOrder","");	//批号
			String strSort = this.getParameter("strSort","");
			if(!"".equals(strOrder)){
				page.setSort(strSort);
				page.setOrder(strOrder);
			}
			
			Integer intNoOn = Integer.valueOf(this.getParameter("intNotOn", "1"));
			if(intNoOn == 0){
				page.addQueryAnd("strCollectionLocationId", QueryType.markEQ, "");
				page.addQueryOr("strCollectionLocationId", QueryType.MarkISNULL, null);
			}
			
			page = libraryService.list(page);
			
			String isExp = this.getParameter("isExp", "");
			if(isExp.equals("1")){
				List<Library> libraryList = page.getDataList();
				String header = "序号,正题名,第一责任者,其他责任者,版本,分册号,分册名,"
						+ "副题名,丛书题名,分类号,分类名,每套册数,每套价格,货币单位,"
						+ "页卷数,出版日期,ISBN,出版者,出版地,书次号,"
						+ "来源,录入日期,批号,图书条码,馆藏位置,书架,现存量,索书号";
				
				String tableStr = "xh,strPositiveTitle,strFirstResponsible,strOtherResponsible,strVersion,strSectionNumber,strSectionName,"
						+ "strSubtitle,strSeriesTitle,strClassNumber,strCategoryName,intNumberCopies,floatPricePer,strCurrencyUnit,strNumberPages,strPublicationDate,strISBN,strPublisher,strPublisherPlace,strBookNumber,strSource,dtCreatDate,strLotNumber,strBookBarcode,strCollectionLocation,strBookshelfName,intExistingStock,strCallNumber";
				
				ExportExcelUtils util = new ExportExcelUtils();
				String path = "upload/exp/";
				String fileName = UuidUtil.get32UUID()+".xls";
				util.exportExcel("图书", ObjUtil.strToList(header), ObjUtil.strToList(tableStr),libraryList, path, fileName);
				
				result.put("path", path);
				result.put("fileName", fileName);
			}else{
				result = this.returnPage(result, page);
			}
			
		}
		
		ResponseUtil.writeJson(result, response);

	}

	/**
	 *是否借出
	 * @param strBookBarcode
	 * @param strSchoolId
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value="/strBookBarcode/{strBookBarcode}/{strSchoolId}",method=RequestMethod.POST)
	public void getStrBookBarcode(@PathVariable String strBookBarcode,@PathVariable String strSchoolId,
								  HttpServletRequest request, HttpServletResponse response) throws Exception{
		HandlerResult result = this.checkToken(request);
		if(result.getCode()==0){
			Library library=libraryService.strBookBarcode(strBookBarcode,strSchoolId);
			result.put("library",library);
		}
		ResponseUtil.writeJson(result, response);
	}
	
	/**
	 * 添加处理
	 * @param obj
	 * @param response
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@SysLog(type=LogType.CATALOGUING)
	public void add(@RequestBody Library obj,HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		HandlerResult result = this.checkToken(request);
		if (result.getCode()==0) {
			try{
				
				String strSchoolId = GlobaUser.getStrSchoolId(request.getHeader("token"));
				
				String strClassNumber = obj.getStrClassNumber();
				ChineseClassification chineseClassification = chineseClassificationService.findByCode(strClassNumber,GlobaUser.getStrSchoolId(request.getHeader("token")));
				String strRepeatBookBarcode = "";
				
				if(chineseClassification!=null){
					Config config = configService.findBySchoolId(GlobaUser.getStrSchoolId(request.getHeader("token")));
					int intLength = config.getIntEffectiveLength();
					intLength = intLength==0?6:intLength;
					
					String strBookBarcode = obj.getStrBookBarcode();
					if(strBookBarcode.length()>intLength){
						intLength = strBookBarcode.length();
					}
					
					int bookBarcode = Integer.valueOf(strBookBarcode);
					Integer intReservationRoyalty = obj.getIntReservationRoyalty();
					intReservationRoyalty = intReservationRoyalty==null ?1:intReservationRoyalty;
					if(intReservationRoyalty != null && intReservationRoyalty>0){
						for(int i=0;i<intReservationRoyalty;i++){
							
							String tempCode = bookBarcode +"";
							int codeLength = tempCode.length();
							if(tempCode.length()<intLength){
								for(int j=0;j<intLength-codeLength;j++){
									tempCode = "0"+tempCode;
								}
							}
							Library library = libraryService.findByBookBarcode(tempCode, strSchoolId);
							if(library==null){
								init(obj);
								obj.setStrBookBarcode(tempCode);
								
								obj.setStrCallNumber(strClassNumber+" "+obj.getStrBookNumber());
								obj.setStrCategoryName(chineseClassification.getStrNodeName());
								obj.setStrCurrencyUnit("人民币");
								obj.setIntNumberLoans(0);					//借出次数  
								obj.setIntIsLogoff(0);				//是否注销  
								obj.setIntExistingStock(1);
								obj.setIntTotaIinventory(1);
								libraryService.add(obj);
								bookBarcode++;
							}else{
								strRepeatBookBarcode += strRepeatBookBarcode.equals("")?tempCode:(","+tempCode);
							}
						}
					}
					String tempCode = bookBarcode +"";
					int codeLength = tempCode.length();
					if(tempCode.length()<intLength){
						for(int j=0;j<intLength-codeLength;j++){
							tempCode = "0"+tempCode;
						}
					}
					result.put("strBookBarcode", tempCode);
					if(!strRepeatBookBarcode.equals("")){
						result.setCode(1);
						result.setMessage("已存在："+strRepeatBookBarcode+"图书条码，请重新分配条码");
					}
				}else{
					result.setCode(1);
					result.setMessage("分类号无效");
				}
				
			}catch(Exception e){
				result.setCode(1);
				e.printStackTrace();
				throw e;
			}
		}
		ResponseUtil.writeJson(result, response);
	}
	
	@RequestMapping(value="/update",method=RequestMethod.POST)
	@SysLog(type=LogType.BOOKMODIFY)
	public void update(@RequestBody Library obj,HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		HandlerResult result = this.checkToken(request);
		if (result.getCode()==0) {
			try{
				String strClassNumber = obj.getStrClassNumber();
				ChineseClassification chineseClassification = chineseClassificationService.findByCode(strClassNumber,GlobaUser.getStrSchoolId(request.getHeader("token")));
				
				if(chineseClassification!=null){
					obj.setStrCategoryName(chineseClassification.getStrNodeName());
					libraryService.update(obj);
				}else{
					result.setCode(1);
					result.setMessage("分类号无效");
				}
			}catch(Exception e){
				result.setCode(1);
				e.printStackTrace();
				throw e;
			}
		}
		ResponseUtil.writeJson(result, response);
	}
	
	/**
	 * 删除处理
	 * @param strId
	 * @return
	 */
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	public void delete(@RequestBody ParamModel paramModel,HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		HandlerResult result = this.checkToken(request);
		if (result.getCode()==0) {
			try{
				String strId = paramModel.getStrId();
				if(strId != null && !strId.equals("")){
					libraryService.deleteMore(strId.split(","));
				}
			}catch(Exception e){
				result.setCode(1);
				e.printStackTrace();
				throw e;
			}
		}
		ResponseUtil.writeJson(result, response);
	}
	
	
	@RequestMapping(value="/view")
	public void view(@RequestBody ParamModel paramModel,HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		HandlerResult result = this.checkToken(request);
		if (result.getCode()==0) {
			try{
				String strSchoolId = GlobaUser.getStrSchoolId(request.getHeader("token"));
				String strId = paramModel.getStrId();
				Library obj = libraryService.findById(strId);
				result.put("obj", obj);
				
				Page page = new Page();
				page.addQueryAnd("strISBN", obj.getStrISBN());
				page.addQueryAnd("strSchoolId", GlobaUser.getStrSchoolId(request.getHeader("token")));
				page.setUsePage(false);
				int allCount = libraryService.list(page).getTotalResult();
				
				page = new Page();
				page.addQueryAnd("strBookBarcode", obj.getStrBookBarcode());
				page.addQueryAnd("strSchoolId", GlobaUser.getStrSchoolId(request.getHeader("token")));
				int count = borrowBookRecordService.findCount(page);
				result.put("borrowCount", count);
				
				BorrowBook borrowBook = borrowBookService.findByBookBarcode(obj.getStrBookBarcode(), strSchoolId);
				if(borrowBook!=null){
					Reader reader = readerService.findByCardNumber(borrowBook.getStrReaderCardNumber(), strSchoolId);
					result.put("currentReaerName", reader!=null?reader.getStrName():"");
					result.put("currentReaerNumber", borrowBook.getStrReaderCardNumber());
					result.put("currentInventory", 0);
					result.put("allCount", allCount);
				}else{
					result.put("currentInventory", 1);
				}
				
				page = new Page();
				page.addQueryAnd("l.strISBN", obj.getStrISBN());
				page.addQueryAnd("l.strSchoolId", GlobaUser.getStrSchoolId(request.getHeader("token")));
				page.setUsePage(false);
//				page.addQueryAnd("r.strSchoolId", result.get("strSchoolId"));
				page.addQueryAnd("l.strSchoolId", result.get("strSchoolId"));
				
				int lossCount = bookLossService.listInfo(page).getTotalResult();
				result.put("lossCount", lossCount);
				
				
			}catch(Exception e){
				result.setCode(1);
				e.printStackTrace();
				throw e;
			}
		}
		ResponseUtil.writeJson(result, response);
	}
	
	@RequestMapping(value="/getLibrary")
	public void getLibrary(@RequestBody Library library,HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		HandlerResult result = this.checkToken(request);
		if (result.getCode()==0) {
			try{
				String strSchoolId = GlobaUser.getStrSchoolId(request.getHeader("token"));
				
				String strBookBarcode = library.getStrBookBarcode();
				Library obj = libraryService.findByBookBarcode(strBookBarcode, strSchoolId);
				result.put("obj", obj);
			}catch(Exception e){
				result.setCode(1);
				e.printStackTrace();
				throw e;
			}
		}
		ResponseUtil.writeJson(result, response);
	}
	
	/**
	 * 修改处理
	 * @param strId
	 * @return
	 */
	@RequestMapping(value="/updatePosition",method=RequestMethod.POST)
	public void updatePosition(@RequestBody Library library,HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		HandlerResult result = this.checkToken(request);
		if (result.getCode()==0) {
			try{
				String strCollectionLocation = library.getStrCollectionLocation();
				String strCollectionLocationId = library.getStrCollectionLocationId();
				String strBookshelf = library.getStrBookshelf();
				String strBookshelfName = library.getStrBookshelfName();
				
				String[] strIds = library.getStrId().split(",");
				for(String strId:strIds){
					Library tempLibrary = libraryService.findById(strId);
					
					CollectionChange collectionChange = new CollectionChange();
					collectionChange.setStrSourceCollection(tempLibrary.getStrCollectionLocation());
					collectionChange.setStrSourceCollectionId(tempLibrary.getStrCollectionLocationId());
					collectionChange.setStrSourcBookshelf(tempLibrary.getStrBookshelfName());
					collectionChange.setStrSourcBookshelfId(tempLibrary.getStrBookshelf());
					
					tempLibrary.setStrCollectionLocation(strCollectionLocation);
					tempLibrary.setStrCollectionLocationId(strCollectionLocationId);
					tempLibrary.setStrBookshelf(strBookshelf);
					tempLibrary.setStrBookshelfName(strBookshelfName);
					libraryService.update(tempLibrary);
					
					init(collectionChange);
					collectionChange.setStrBookBarcode(tempLibrary.getStrBookBarcode());
					collectionChange.setStrNewCollection(strCollectionLocation);
					collectionChange.setStrNewCollectionId(strCollectionLocationId);
					collectionChange.setStrNewBookshelf(strBookshelfName);
					collectionChange.setStrNewBookshelfId(strBookshelf);
					collectionChange.setStrPositiveTitle(tempLibrary.getStrPositiveTitle());
					collectionChangeService.add(collectionChange);
				}
			}catch(Exception e){
				result.setCode(1);
				e.printStackTrace();
				throw e;
			}
		}
		ResponseUtil.writeJson(result, response);
	}
	
	@RequestMapping(value="/getMaxBookNumber",method=RequestMethod.POST)
	public void getMaxBookNumber(@RequestBody Library obj,HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		HandlerResult result = this.checkToken(request);
		if (result.getCode()==0) {
			try{
				String max = "";
				String strClassNumber = obj.getStrClassNumber();
				ChineseClassification chineseClassification = chineseClassificationService.findByCode(strClassNumber,GlobaUser.getStrSchoolId(request.getHeader("token")));
				DecimalFormat g1=new DecimalFormat("0000");
				
				if(chineseClassification!=null){
					String bookNumber = libraryService.getMaxBookNumber(strClassNumber, GlobaUser.getStrSchoolId(request.getHeader("token")));
					if(bookNumber!=null && !bookNumber.equals("")){
						max = String.valueOf(Integer.parseInt(bookNumber) + 1);
						for (int i = max.length(); i <= 3; i++) {
							max = "0" + max;
						}
					}else{
						max = "0001";
					}
					result.put("strBookNumber",max);
				}else{
					result.setCode(1);
					result.setMessage("分类号无效");
				}
			}catch(Exception e){
				result.setCode(1);
				e.printStackTrace();
				throw e;
			}
		}
		ResponseUtil.writeJson(result, response);
	}
	
	
	@RequestMapping(value="/getLibraryOnline")
	public void getLibraryOnline(HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		HandlerResult result = this.checkToken(request);
		if (result.getCode()==0) {
			try{
				String url = "http://opac.gzlib.gov.cn/opac/search?";
				
				String keyName = this.getParameter("keyName", "");
				String keywords = this.getParameter("keywords", "");
				if(!keyName.equals("")){
					if("strISBN".equals(keyName)){
						url += "q="+keywords+"&searchWay=isbn&scWay=dim";
					}
					if("strPositiveTitle".equals(keyName)){
						url += "q="+keywords+"&searchWay=title200a&scWay=dim";
					}
				}
				
//				String strISBN = this.getParameter("strISBN","");	//ISBN
//				String strPositiveTitle = this.getParameter("strPositiveTitle","");	//ISBN
				
//				String ISBN = "7-81045-369-6";
				//&searchWay=isbn&scWay=dim&hasholding=1&searchSource=reader
//				String url = "http://opac.gzlib.gov.cn/opac/search?q="+ISBN+"&searchWay=isbn&scWay=dim";
				String temp = HttpClientUtil.doGet(url);
				System.out.println(temp);
				
				String bookrecno = RegUtil.getSubUtilSimple(temp, "(?i)express_bookrecno=\"(.*?)\"");
				if(!bookrecno.equals("")){
					String viewUrl = "http://opac.gzlib.gov.cn/opac/book/"+bookrecno+"?view=simple";
					String tempContent = HttpClientUtil.doGet(viewUrl);
					tempContent = tempContent.trim().replace("<!--","").replace("-->","");
					
					tempContent = tempContent.substring(tempContent.indexOf("<tr>"),tempContent.lastIndexOf("</tr>")+5);
					tempContent = Format.toWorld(tempContent.replace("	", ""));
					tempContent = "<table>"+tempContent+"</table>";
					System.out.println(tempContent);
					
					HtmlCleaner hc = new HtmlCleaner();
					TagNode tn = hc.clean(tempContent);
					Document dom = new DomSerializer(new CleanerProperties()).createDOM(tn);
					XPath xPath = XPathFactory.newInstance().newXPath();
					
					String value  = "";
					String strISBN = "";
					String floatPricePer = "";
					String strPositiveTitle = "";
					String strFirstResponsible = "";
					String strPublisher = "";
					String strPublisherPlace = "";
					String strPublicationDate = "";
					String strClassNumber = "";
					String strNumberPages = "";
					try{
						value  = parseString(xPath,dom, "//tr[position()=1]/td[position()=2]");
						strISBN = RegUtil.getSubUtilSimple(value, "(.*?)价格：");
						floatPricePer = RegUtil.getSubUtilSimple(tempContent, "价格：CNY(.*?)</td>");
						floatPricePer = RegUtil.getMatchStr(floatPricePer, "[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*");
						
						strPositiveTitle = parseString(xPath,dom, "//td/a");
						strFirstResponsible = parseString(xPath,dom, "//td/a[starts-with(@href,'/opac/search?searchWay=author')]");
						strPublisher = parseString(xPath,dom, "//td/a[starts-with(@href,'/opac/search?searchWay=publisher')]");
						strPublisherPlace = RegUtil.getSubUtilSimple(tempContent, "出版地：(.*?)出版");
						strPublicationDate = RegUtil.getSubUtilSimple(tempContent, "出版日期：(.*?)</td>");
						strClassNumber = RegUtil.getSubUtilSimple(tempContent, "中图分类:</div></td><td class=\"rightTD\">([A-Z]*)[0-9]");
						strNumberPages = RegUtil.getSubUtilSimple(tempContent, "载体形态:</div></td><td class=\"rightTD\">(.*?)页")+"页";
					}catch(Exception e){
						e.printStackTrace();
					}
					
					Library library = new Library();
					library.setStrISBN(strISBN);
					library.setFloatPricePer(Float.valueOf(floatPricePer!=null&&!floatPricePer.equals("")?floatPricePer:"0"));
					library.setStrPositiveTitle(strPositiveTitle);
					library.setStrFirstResponsible(strFirstResponsible);
					library.setStrPublisher(strPublisher);
					library.setStrPublisherPlace(strPublisherPlace);
					library.setStrPublicationDate(strPublicationDate);
					library.setStrClassNumber(strClassNumber);
					library.setStrNumberPages(strNumberPages);
//					
					result.put("obj",library);
				}
				
			}catch(Exception e){
				result.setCode(1);
				e.printStackTrace();
				throw e;
			}
		}
		ResponseUtil.writeJson(result, response);
	}
	
	public static String parseString(XPath xPath,Object node,String expression) {
		//获取当前这个node下的符合这个属性的节点
		try {
			Object tempNode = xPath.evaluate(expression, node, XPathConstants.NODESET);
			
			
			if(tempNode instanceof NodeList) {
				NodeList tempList = (NodeList)tempNode;
				if(tempList.getLength() > 0) {
					String value = tempList.item(0).getTextContent();
					return value;
				}
			}
		}catch(Exception e) {
			e.printStackTrace();
		}
		return null;
		
	}
	
	public static void main(String[] args) throws Exception{
//		 9787119016627
		String temp = HttpClientUtil.doGet("http://opac.gzlib.gov.cn/opac/search?q=978-7-02-000873-5&searchWay=isbn&scWay=dim");
		System.out.println(temp);
		
		String bookrecno = RegUtil.getSubUtilSimple(temp, "(?i)express_bookrecno=\"(.*?)\"");
		
		String viewUrl = "http://opac.gzlib.gov.cn/opac/book/"+bookrecno+"?view=simple";
		String tempContent = HttpClientUtil.doGet(viewUrl);
		tempContent = tempContent.trim().replace("<!--","").replace("-->","");
		
		tempContent = tempContent.substring(tempContent.indexOf("<tr>"),tempContent.lastIndexOf("</tr>")+5);
		tempContent = Format.toWorld(tempContent.replace("	", ""));
		tempContent = "<table>"+tempContent+"</table>";
		System.out.println(tempContent);
		
		HtmlCleaner hc = new HtmlCleaner();
		TagNode tn = hc.clean(tempContent);
		Document dom = new DomSerializer(new CleanerProperties()).createDOM(tn);
		XPath xPath = XPathFactory.newInstance().newXPath();
		
		String value  = parseString(xPath,dom, "//tr[position()=1]/td[position()=2]");
		String strISBN = RegUtil.getSubUtilSimple(value, "(.*?)价格：");
		String floatPricePer = RegUtil.getSubUtilSimple(tempContent, "价格：CNY(.*?)</td>");
		System.out.println(floatPricePer+"=============");
		floatPricePer = RegUtil.getMatchStr(floatPricePer, "[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*");
		
		System.out.println(floatPricePer+"=============");
	}
}
